package com.zhoufy;

import com.mongodb.MongoClient;
import com.mongodb.client.FindIterable;
import com.mongodb.client.MongoCollection;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.model.Filters;
import org.bson.Document;

/**
 * Created with IntelliJ IDEA by ChouFy on 2020-07-25.
 *
 * @author chouFy
 */
public class MongoDatabaseJavaDemo {


    public static void main(String[] args) {
        MongoClient client = new MongoClient("localhost", 27017);

        MongoDatabase mongoDatabase = client.getDatabase("lg_resume");

        MongoCollection<Document> mongoCollection = mongoDatabase.getCollection("lg_resume_preview");


        Document parse = Document.parse("{name:'周芳禹'}");


        Document desc = new Document();
        desc.append("expectSalary", 1);

        FindIterable<Document> documents = mongoCollection.find(Document.parse("{'name':'周芳禹'}")).sort(desc);


        for (Document document : documents) {
            System.out.println(document);
        }



        mongoCollection.deleteOne(Document.parse("{'_id':'5f171985742f6e4e4dc4876a'}"));

        System.out.println("========");

        documents = mongoCollection.find(Filters.and(Filters.eq("name", "周芳禹") , Filters.eq("id", "5f1858c9742f6e4e4dc4876b"))).sort(desc);

        for (Document document : documents) {
            System.out.println(document);
        }

        client.close();

    }
}
